﻿CREATE PROCEDURE [dbo].[UpdateActivityLink]
	@Activity1 uniqueidentifier,
	@Activity2 uniqueidentifier,
	@Condition nvarchar(max),
	@Comment nvarchar(max),
    @IsDeleted bit,
    @LastChanged datetime,
	@LastChangedBy uniqueidentifier,

	@TimeStamp timestamp,
	@newTimeStamp timestamp output

AS

	UPDATE ActivityLink

	SET 
	 Condition = @Condition,
	 Comment = @Comment,
	 IsDeleted = @IsDeleted, 
	 LastChanged = @LastChanged,
	 LastChangedBy = @LastChangedBy

	WHERE Activity1 = @Activity1 AND Activity2 = @Activity2 AND [TimeStamp]=@TimeStamp

  IF @@ROWCOUNT = 0

    RAISERROR('Row has been edited by another user', 16, 1)            	


	SELECT @newTimeStamp = [TimeStamp]

	FROM ActivityLink 

	WHERE Activity1 = @Activity1 AND Activity2 = @Activity2

RETURN 0